package io.xccit.controller;

import io.xccit.pojo.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * @author Xccit
 * @Date 2023-02-08
 * @Description
 */
@Controller
public class IndexController {
    @RequestMapping("/")
    public String index(){
        return "index";
    }
    @RequestMapping("test/{id}/{username}")
    public String test(@PathVariable("id") Integer id,@PathVariable("username") String username){
        System.out.println("id:"+id+"  username:"+username);
        return "success";
    }
    @RequestMapping("param1")
    public String getParam1(HttpServletRequest request){
        HttpSession session = request.getSession();
        String username = request.getParameter("username");
        String password = request.getParameter("password");
        System.out.println("username:"+username+" password:"+password);
        return "success";
    }
    @RequestMapping("param2")
    public String getParam2(String username,String password){
        System.out.println("username:"+username+" password:"+password);
        return "success";
    }
    @RequestMapping("param3")
    public String getParam3(@RequestParam("username") String param1,@RequestParam("password") String param2){
        System.out.println("username:"+param1+" password:"+param2);
        return "success";
    }
    @RequestMapping("header")
    public String getHeader(@RequestHeader("User-Agent") String userAgent){
        System.out.println("User-Agent:"+userAgent);
        return "success";
    }
    @RequestMapping("cookie")
    public String getCookie(@CookieValue("JSESSIONID") String jsessionID){
        System.out.println("JSESSIONID:"+jsessionID);
        return "success";
    }
    @RequestMapping(value = "pojo")
    public String getParamForPojo(User user){
        System.out.println(user.getSex());
        System.out.println(user);
        return "success";
    }
}
